<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../static/userinfoPrivate/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../static/css/thesame.css" media="all">
    <link rel="stylesheet" href="../static/css/footer.css" media="all">
    <link rel="stylesheet" href="../static/userinfoPrivate/layer/theme/default/layer.css" media="all">
    <link rel="stylesheet" href="../static/css/drugs/rightCon.css" media="all">
    <link rel="stylesheet" href="../static/css/drugs/tree.css" media="all">
    <style>
        /* 用药管理-新增药物 */
        .layui-time-img input, .layui-time {
            background: url(../static/img/icon_time.png) no-repeat right 10px center;
            width: 100%;
        }
    </style>
</head>

<body class="layui-layout-body">
<div class="layui-body">
    <div class="add-title pad25px"><span class="mr10px cursor return"><img src="../static/img/return_icon.png"></span><span>新增药物登记</span></div>
    <div class="new-add-box new-add-box-width bgWhite box-shadows border-radius4">
        <div class="new-add-box-scroll">
            <div class="add-mess add-mess-mb mar25px">
                <article class="overflow">
                    <div class="add-mess-child">
                        <div>
                            <label><em class="red">*</em>药物名称：</label>
                        </div>
                        <div class="add-mess-form">
                            <p><input type="text" id="meicineName" placeholder="请输入名称" maxlength="50"></p>
                        </div>
                    </div>
                    <div class="add-mess-child">
                        <div>
                            <label><em class="red">*</em>药物属性：</label>
                        </div>
                        <div class="add-mess-form">
                            <p>
                                <select name="" id="meicineNature" class="form-select">
                                    <option value="101">普通药物</option>
                                    <option value="102">精神药物</option>
                                </select>
                            </p>
                        </div>
                    </div>
                    <div class="add-mess-child">
                        <div>
                            <label><em class="red">*</em>登记时间：</label>
                        </div>
                        <div class="add-mess-form">
                            <p>
                                <input type="text" id="registerDate" readonly="readonly" placeholder="请输入" class="layui-time test-item">
                            </p>
                        </div>
                    </div>
                    <div class="add-mess-child">
                        <div>
                            <label>厂家：</label>
                        </div>
                        <div class="add-mess-form">
                            <p>
                                <input type="text" id="manufactureFactory" placeholder="请输入药物厂家" maxlength="60">
                            </p>
                        </div>
                    </div>
                    <div class="add-mess-child">
                        <div>
                            <label>规格：</label>
                        </div>
                        <div class="add-mess-form">
                            <p>
                                <input type="text" id="specification" placeholder="请输入药物规格" maxlength="60">
                            </p>
                        </div>
                    </div>
                    <div class="add-mess-child">
                        <div>
                            <label>数量：</label>
                        </div>
                        <div class="add-mess-form">
                            <p>
                                <input type="text" id="medicineCount" placeholder="请输入药物数量" maxlength="10">
                            </p>
                        </div>
                    </div>
                    <div class="add-mess-child">
                        <div>
                            <label>批号：</label>
                        </div>
                        <div class="add-mess-form">
                            <p>
                                <input type="text" id="batchNumber" placeholder="请输入药物批号" maxlength="30">
                            </p>
                        </div>
                    </div>
                    <div class="add-mess-child">
                        <div>
                            <label><em class="red">*</em>有效期：</label>
                        </div>
                        <div class="add-mess-form">
                            <p>
                                <input type="text" id="validityDate" class="layui-time test-item" placeholder="请选择" readonly="readonly">
                            </p>
                        </div>
                    </div>
                    <div class="add-mess-child">
                        <div>
                            <label>服法：</label>
                        </div>
                        <div class="add-mess-form">
                            <p>
                                <input type="text" id="useMethod" placeholder="请输入药物服法" maxlength="30">
                            </p>
                        </div>
                    </div>
                    <div class="add-mess-child">
                        <div>
                            <label>药量结束时间：</label>
                        </div>
                        <div class="add-mess-form">
                            <p>
                                <input type="text" id="userEndDtate" class="layui-time test-item" readonly="readonly" placeholder="请选择">
                            </p>
                        </div>
                    </div>
                    <div class="add-mess-child">
                        <div>
                            <label><em class="red">*</em>家属姓名：</label>
                        </div>
                        <div class="add-mess-form">
                            <p>
                                <input type="text" id="familyName" placeholder="送药过来的家属姓名" maxlength="30">
                            </p>
                        </div>
                    </div>

                </article>
            </div>
        </div>
    </div>
</div>
<div class="layui-footer layui-footer-one">
    <div class="btn-con textCenter">
        <span class="btn-one cursor return">返&nbsp;回</span>
        <span class="btn-two cursor" onclick="registerDrugs()">提&nbsp;交</span>
    </div>
</div>
<script src="../static/js/jquery-2.1.3.min.js"></script>
<!--<script src="../static/layui/layui.js" charset="utf-8"></script>-->
<script src="../static/layer/layer.js" charset="utf-8"></script>
<script type="text/javascript" src="../static/laydate/laydate.js"></script>

<script th:inline="javascript">

    var userNo = [[${userNo}]]

    $(function () {
        console.log(userNo);

        lay('.test-item').each(function () {
            laydate.render({
                elem: this,
                trigger: 'click',
                /*value: '1989-10-14'*/
            });
        });


        $(".return").click(function () {
            window.history.back();
        })


    });

    function registerDrugs() {

        var familyName = $("#familyName").val();
        var userEndDtate = $("#userEndDtate").val();
        var useMethod = $("#useMethod").val();
        var validityDate = $("#validityDate").val();
        var batchNumber = $("#batchNumber").val();
        var medicineCount = $("#medicineCount").val();
        var specification = $("#specification").val();
        var manufactureFactory = $("#manufactureFactory").val();
        var registerDate = $("#registerDate").val();
        var meicineNature = $("#meicineNature").val();
        var meicineName = $("#meicineName").val();
        if (isNull(meicineName)) {
            layer.msg("请输入药名")
            return;
        }

        if (isNull(registerDate)) {
            layer.msg("请输入登记时间")
            return;
        }

        if (isNull(validityDate)) {
            layer.msg("请输入有效期")
            return;
        }


        /*if (isNull(userEndDtate)) {
            layer.msg("请输入药量结束时间")
            return;
        }*/

        if (isNull(familyName)) {
            layer.msg("请输入家属姓名")
            return;
        }
        var data = {
            familyName: familyName, userEndDtate: userEndDtate, useMethod: useMethod, validityDate: validityDate,
            batchNumber: batchNumber, medicineCount: medicineCount, specification: specification, userNo: userNo,
            manufactureFactory: manufactureFactory, registerDate: registerDate, meicineNature: meicineNature, meicineName: meicineName
        };
        $.ajax({
            url: "../medicine/addUserMedicine",
            type: "post",
            async: false,
            dataType: "json",
            data: data,
            success: function (result) {
                if (result.code == 200) {
                    layer.alert("保存成功", function () {
                        window.location.href = "../medicine/toGrantPage?userNo=" + userNo;
                    })
                } else {
                    layer.msg(result.msg);
                }
            }
        })
    }


    function isNull(value) {
        return value == null || value === "" || value === undefined;
    }

</script>
</body>

</html>
